package com.example.android_pro;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.example.android_pro.ui.SettingItemView;

public class SettingActivity extends Activity {
	private SettingItemView siv_update;
	private SharedPreferences sp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		sp = getSharedPreferences("config", MODE_PRIVATE);
		siv_update = (SettingItemView) findViewById(R.id.siv_update);

		boolean update = sp.getBoolean("update", false);
		if (update) {
			siv_update.setChecked(false);
			
		} else {
			siv_update.setChecked(true);
			
		}
		siv_update.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Editor editor = sp.edit();
				if (siv_update.isCheckBox()) {
					siv_update.setChecked(false);
					
					editor.putBoolean("update", false);
				} else {
					siv_update.setChecked(true);
					
					editor.putBoolean("update", true);
				}
				editor.commit();

			}
		});
	}

}
